﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EBookStore.Books;

namespace EBookStore.Publishers
{
    class PublisherContactByFax:IPublisher
    {
        /// <summary>
        /// orders book from publisher using fax
        /// </summary>
        /// <param name="b">book to order</param>
        /// <param name="amount">amount of specific book</param>
        /// <returns></returns>
        public bool OrderBook(Book b, int amount)
        {
            string faxData = "[{action:orderBook},[{BookISBN:" + b.ISBN + "}, {amount:" + amount + "}]]}";
            Publisher pub = Management.PublisherManager.Instance.GetPublisher(b.PublisherID);
            string faxNum = Management.PublisherManager.Instance.GetPublisher(b.PublisherID).FaxNumber;
            if (SendFax(pub.FaxNumber, faxData))
            {
                pub.OrderedBooks += amount;
                return true;
            }
            return false;

        }
        /// <summary>
        /// returns book to publisher in case it was cancelled/returned by user
        /// </summary>
        /// <param name="b"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        public bool ReturnBook(Books.Book b, int amount)
        {
            Publisher p = Management.PublisherManager.Instance.GetPublisher(b.PublisherID);
            
            string adress = p.Adress;
            //some serial data that is finally sent by fax
            string faxData = "[{action:returnBook},[{BookISBN:" + b.ISBN + "}, {amount:" + amount + "}]]}";
            //first send fax to notify publisher that book is being returned
            if (SendFax(p.FaxNumber, faxData))
            {                
                //send book by delivery company
                return SendBook(b, p.Adress);
            }
            //fax was not sent...
            return false;
 
        }

        private bool SendFax(string faxNum, string data)
        {
            //TODO:send fax and check status
            return true;
        }
        private bool SendBook(Book b, string adress)
        {
            //TODO:send book to adress
            return true;
        }


    }
}
